package gameStates.gui;

import main.listeners.listenerClasses.gui.ChatActivatedEvent;
import main.listeners.listenerClasses.gui.ConsoleToggleEvent;
import main.listeners.listenerClasses.gui.GUIListener;
import main.listeners.listenerClasses.gui.IngameChangedEvent;
import main.listeners.listenerClasses.gui.ScoreBoardToggleEvent;
import main.listeners.listenerClasses.gui.SpawnMenuChangedEvent;
import main.listeners.listenerClasses.loading.LoadingAbortedEvent;
import main.listeners.listenerClasses.loading.LoadingListener;
import main.listeners.listenerClasses.loading.LoadingStartedEvent;
import main.listeners.listenerClasses.loading.LoadingStoppedEvent;

import gameStates.absGamesStates.gui.AbsConsoleState;
import gameStates.passes.AbsPassManagerState;
import interfaces.console.ConsoleElement;

public class ConsoleState extends AbsConsoleState {
		
	public ConsoleState(AbsPassManagerState passManagerState) {
		super("console", passManagerState, true);
		initInterface();
		
		addListenerToClearer(new GUIListener() {
			@Override
			public void consoleToggled(ConsoleToggleEvent event) {
				setActive(event.getValue());
				setFocus();
			}
			
			@Override
			public void ingameChanged(IngameChangedEvent event) {}
			@Override
			public void spawnMenuChanged(SpawnMenuChangedEvent event) {}
			@Override
			public void scoreBoardToggled(ScoreBoardToggleEvent event) {}
			@Override
			public void chatActivated(ChatActivatedEvent event) {}
		});
		
		addListenerToClearer(new LoadingListener() {
			@Override
			public void loadingStarted(LoadingStartedEvent event) {
				setActive(false);
			}
			
			@Override
			public void loadingStopped(LoadingStoppedEvent event) {}
			@Override
			public void loadingAborted(LoadingAbortedEvent event) {}
		});
	}
	
	public void initInterface() {
		interfaceElement = new ConsoleElement(this);
	}
	
	@Override
	public void enableInput(boolean enable) {
		if(isActive() == enable) super.enableInput(enable);
	}
	
	@Override
	public void setFocus() {
		((ConsoleElement)interfaceElement).setFocus();
	}
	
	@Override
	public void restore() {
		updateDisplaySize();
		((ConsoleElement)interfaceElement).updateConsoleAlignment();
	}
}